<?php
global $_W, $_GPC;
load()->func('tpl');
$html_title = $_W['current_module']['title'];
$op = !empty($_GPC['op']) ? $_GPC['op'] : '';
$extra = !empty($_GPC['extra']) ? $_GPC['extra'] : '';
$active = 'index';

//任务详情
if($op == 'detail'){
    $html_title = '任务详情';
    $id = intval($_GPC['id']);
    $detail = pdo_get('yq_haircircle_task',array('id'=>$id));
    if(empty($detail)){
        ajaxError('不存在该任务');
    }
    $detail['thumb'] = cmf_get_upload_url($detail['thumb']);
    $detail['remark'] = cutstr_html(htmlspecialchars_decode($detail['remark']));
    $detail['validate'] = htmlspecialchars_decode($detail['validate']);
    $detail['surplus'] = $detail['end_time'] - time() + 1;//剩余时间
    $detail['surplus'] = $detail['surplus'] ? $detail['surplus'] : 0;
    $detail['create_time'] = date('Y-m-d H:i:s',$detail['create_time']);
    $user_id = checkMobileLogin() ? session('user_id') : 0;
    $detail['receive_id'] = 0;//未接
    if(!$user_id){
        $detail['receive_status'] = -1;//抢任务。任务还未接取
    }else{
        $result  = pdo_get('yq_haircircle_task_receive',array('taskid'=>$id,'user_id'=>$user_id));
        if(empty($result)){
            $detail['receive_status'] = -1;//抢任务。任务还未接取
        }else{
            $detail['receive_status'] = $result['receive_status'];
            //任务接过了，但是过期了
            if($result['receive_status']==0 && $detail['end_time']<time()){
                $detail['receive_status'] = 1;//任务已失效
                pdo_update('yq_haircircle_task_receive',array('receive_status'=>1),array('taskid'=>$id,'user_id'=>$user_id));
            }
            $detail['receive_id'] = $result['id'];
        }
    }

    include $this->template('task_detail');exit;
}
